{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The well-behaved vector transformations we’re going to focus on are called `linear transformations`. \n",
    "\n",
    "Along with vectors, linear transformations are the other main objects of study in `linear algebra`. Linear transformations are special transformations where vector arithmetic looks the same before and after the transformation."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![image.png](images/6.vectorSum.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The question we want to ask is, if we apply the same vector transformation to all three of the vectors in this diagram, will it still look like a vector sum? Let’s try a vector transformation, which is a counterclockwise rotation about the origin, and call this transformation R. \n",
    "\n",
    "Figure 4.18 shows u, v, and w rotated by the same angle by the transformation R.\n",
    "\n",
    "\n",
    "![image.png](images/7.vectorSumAfterRotation.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The rotated diagram is exactly the diagram representing the vector sum R(u) + R(v) = R(w). You can draw the picture for any three vectors u, v, and w, and as long as u + v = w and if you apply the same rotation transformation R to each of the vectors, you find that R(u) + R(v) = R(w) as well. To describe this property, we say that rotations preserve vector sums."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![image.png](images/8.scalarMultiplication.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Similarly, rotations preserve scalar multiples. If v is a vector and sv is a multiple of v by a scalar s, then sv points in the same direction but is scaled by a factor of s. If we rotate v and sv by the same rotation R, we’ll see that R(sv) is a scalar multiple of R(v) by the same factor s."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Linear transformation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A linear transformation is a vector transformation T that preserves vector addition and scalar multiplication. That is, for any input vectors u and v, we have:\n",
    "\n",
    "$$\n",
    "T(u) + T(v) = T(u+v)\n",
    "$$\n",
    "\n",
    "and for any pair of a scalar s and a vector v, we have:\n",
    "$$\n",
    "T(sv) = sT(v)\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Picturing linear transformations"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## vector transformation that’s not linear won't preserve vector sums"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "First, let’s look at a counterexample: a vector transformation that’s not linear. \n",
    "\n",
    "Such an example is a transformation S(v) that takes a vector v = (x, y) and outputs a vector with both coordinates squared: $S(v) = (x^2 , y^2)$.\n",
    "\n",
    "$\n",
    "S(u) + S(v)\\ !=\\ S(u + v)\n",
    "$\n",
    "\n",
    "S(u) + S(v) does not agree with S(u + v)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## scalar multiple does preserve vector sums"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![image.png](images/9.scalarMultipleDoesPreserveVectorSums.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "D(v) preserves scalar multiplication. This is a bit harder to draw, but you can see it algebraically. For any scalar $s$, $D(sv) = 2(sv) = s(2v) = sD(v)$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## translation is not a linear transformation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![image.png](images/10.translationIsNotAlinearTransformation.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Why linear transformations?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Because linear transformations preserve vector sums and scalar multiples, they also preserve a broader class of vector arithmetic operations. The most general operation is called a linear combination."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## linear combination"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A linear combination of a collection of vectors is a sum of scalar multiples of them. \n",
    "\n",
    "For instance, one linear combination of two vectors `u` and `v` would be `3u - 2v`. Given three vectors `u`, `v`, and `w`, the expression `0.5u - v + 6w` is a linear combination of `u`, `v`, and `w`. Because linear transformations preserve vector sums and scalar multiples, these preserve linear combinations as well."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can restate this fact algebraically. If you have a collection of $n$ vectors, $v_1 , v_2 , ..., v_n$, as well as any choice of $n$ scalars, $s_1 , s_2 , s_3 , ..., s_n$ , a linear transformation $T$ preserves the linear combination:\n",
    "\n",
    "$\n",
    "T(s_1 V_1 + s_2 V_2 + s_3 V_3 + ... + s_n V_n) = s_1 T(V_1) + s_2 T(V_2) + s_3 T(V_3) + ... + s_n T(V_n)\n",
    "$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![image.png](images/11.exampleOfLinearCombination1.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## linear transformations send every existing line segment to a new line segment"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![image.png](images/12.weightedAverage1.png)\n",
    "![image.png](images/13.weightedAverage2.png)\n",
    "![image.png](images/14.weightedAverage3.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "yingshaoxo: In a another words, what `linear transformation` does is to send every point on the line segment connecting `u` and `v` to a point on a line segment that connecting `T(u)` and `T(v)`.\n",
    "\n",
    "For example:\n",
    "\n",
    "![image.png](images/15.linearTransformationExample.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In summary, linear transformations respect the algebraic properties of vectors, preserving sums, scalar multiples, and linear combinations. They also respect the geometric properties of collections of verctors, sending line segments and polygons defined by vectors to new ones defined by the transformed vectors."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Computing linear transformations"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![image.png](images/16.3DvectorMadeFromCombinations.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Any 3D vector can be decomposed into a linear combination of three vectors (1, 0, 0), (0, 1, 0), and (0, 0, 1). The scalars appearing in this decomposition for a vector v are exactly the coordinates of v."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "T(v) = T(3e_1 + 2e_2 ) = 3T(e_1 ) + 2T(e_2 )\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![image.png](images/17.calculation.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Exercise 4.17\n",
    "\n",
    "![image.png](images/18.exercise4.17.png)\n",
    "\n",
    "![image.png](images/19.exercise4.19.png)\n",
    "\n",
    "![image.png](images/20.exercise4.20.png)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Exercise 4.21\n",
    "\n",
    "![image.png](images/21.exercise4.21.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
